using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : StateBase<PlayerController>
{
    private float m_PreviousAnimationSpeed;
    public Move(PlayerController owner) : base(owner)
    {
    }

    private void OnJumpListener()
    {
        m_Owner.Jump();
    }
    public override void OnEnter()
    {
        m_Owner.Animator.SetTrigger(m_Owner.AnimatorParameter_Move);
        m_PreviousAnimationSpeed = m_Owner.Animator.speed;
        m_Owner.OnJumpButtonDown += OnJumpListener;
    }
    public override void Update()
    {
        if (m_Owner.MoveFactor == 0)
        {
            m_Owner.ChangeState(m_Owner.IdleState);
        }
    
    }
    public override void FixedUpdate()
    {
        m_Owner.Move();
        m_Owner.Animator.speed = (Mathf.Abs(m_Owner.Rigidbody.velocity.x) / m_Owner.maxMoveSpeed_Base) * (1 / m_Owner.GetScale(true));
    }

    public override void OnExit()
    {
        m_Owner.Animator.speed = m_PreviousAnimationSpeed;
        m_Owner.OnJumpButtonDown -= OnJumpListener;
    }
}
